<template>
    <view class="conversion">
        <view class="modtwo">
            <view class="bitile">
                接受账号
            </view>
            <view class="inps">
                <input v-model="zham" type="text" placeholder="请输入账号" />
            </view>
            <view class="bitile">
                转出币种
            </view>
            <view class="celldb">
                <picker mode=selector @change="bindPickerChange" :value="index" :data-id="array[index].val" :range="array" range-key="bizhong">
                    <view class="uniinput">{{array[index].bizhong}}</view>
                    <image @change="bindPickerChange" src="../../static/img/jjj.png"></image>
                </picker>

            </view>
            <view class="bitile">
                转出数量
            </view>
            <view class="inps">
                <input v-model="conte" type="text" placeholder="请输入转出数量" />
            </view>
            <view class="bitile">
                手续费
            </view>
            <view class="inps">
                <view class='feepri'>
                    {{feepri}}
                </view>
            </view>
            <view class="bitile">
                支付密码
            </view>
            <view class="inps">
                <input v-model="transPwds" type="text" placeholder="请输入支付密码" />
            </view>
        </view>
        <view class="timo" @click="hzFn">确定</view>
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
    export default {
        data() {
            return {
                index: 0,
                array: [{
                    bizhong: 'usdt',
                    val: 'usdt'
                }],
                codeBtn: {
                    codeTime: 60,
                    codeText: "获取验证码",
                    codeStatus: true,
                },
                zham: '',
                conte: '',
                transPwds: '',
                yzcode: "",
                feepri: '',
                usd:'usdt'
            }
        },
        onLoad() {
            uinfo = uni.getStorageSync('userInfo');
            this.sfee();
        },
        methods: {
            bindPickerChange: function(e) {
                console.log(e.currentTarget.dataset.id)
                this.usd=e.currentTarget.dataset.id;
                this.index = e.target.value
            },
            //互转
            hzFn() {
                let telEmail = '';
                if (uinfo.userLoginInfo.email == null) {
                    telEmail = uinfo.userLoginInfo.mobile;
                } else {
                    telEmail = uinfo.userLoginInfo.email;
                }
                if (this.zham == '') {
                    return uni.showToast({
                        icon: "none",
                        title: '请输入账号',
                    });
                }

                if (this.conte == '') {
                    return uni.showToast({
                        icon: "none",
                        title: '请输入数量',
                    });
                }
                if (this.transPwds == '') {
                    return uni.showToast({
                        icon: "none",
                        title: '请输入支付密码',
                    });
                }
                uni.showLoading({
                    mask: true
                });
                request.postAssets('/assets/userWallet/transfer', {
                    accountNumber: telEmail, //手机或邮箱 ,
                    amount: this.conte, //转出数量 ,
                    chain: 'tron',
                    coin: this.usd,
                    // note (string, optional): 备注 ,
                    toAccount: this.zham, //接受账号,
                    transPwd: this.transPwds, //支付密码 ,
                    //verifyCode: this.yzcode, //验证码                
                    userId: uinfo.userId,
                }).then(res => {
                    console.log(res)
                    if (res.code == '200') {
                        uni.hideLoading();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                        uni.switchTab({
                            url: '/pages/mine/mine',
                        });
                    } else {
                        uni.hideLoading();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
            //获取验证码
            getPhonecode() {
                //0手机号，1邮箱
                let telEmail = '0';
				let accountNumber;
                if (uinfo.userLoginInfo.email == null) {
                    telEmail = '0';
					accountNumber = uinfo.userLoginInfo.mobile;
                } else {
                    telEmail = '1';
					accountNumber = uinfo.userLoginInfo.email;
                }
                if (this.codeBtn.codeStatus) {
                    this.codeBtn.codeStatus = false;
                    let timerId = setInterval(() => {
                        let codetime = this.codeBtn.codeTime;
                        codetime--;
                        this.codeBtn.codeTime = codetime;
                        this.codeBtn.codeText = "剩余" + codetime + "秒";
                        if (codetime < 1) {
                            clearInterval(timerId);
                            this.codeBtn.codeText = "重新获取";
                            this.codeBtn.codeTime = 60;
                            this.codeBtn.codeStatus = true;
                        }
                    }, 1000);
                    request.postMember('/user/login/sendVerifiyCode', {
                        accountNumber: accountNumber,
                        businessType: '3',
                        accountType: telEmail
                    }).then(res => {
                        console.log(res)


                        if (res.code == "200") {

                            uni.showToast({
                                icon: "none",
                                title: '发送成功',
                            });
                        } else {
                            uni.showToast({
                                icon: "none",
                                title: res.message,
                            });
                        }
                    })
                }
            },
            sfee() {
                //手续费接口//tx_fee:交易手续费
                request.postAssets('/assets/userWallet/queryDataDictionary', {
                    key: 'tx_fee'
                }).then(res => {
                    //console.log(res)
                    if (res.code == '200') {
                        this.feepri = res.data.value;
                    }
                })
            },
        }
    }
</script>

<style>
    .conversion {
        padding: 20px 0 50px 0;
        background-color: #F5F5F5;
    }

    .modtwo {
        width: 710rpx;
        background-color: #FFFFFF;
        border-radius: 8px;
        margin: 0 auto;
        padding: 10px 0 30px 0;
    }

    .modtwo .bitile {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 27px;
        color: #333333;
        margin: 10px 10px 15px;
    }

    .modtwo .inps {
        border-bottom: 1px solid #EBEBEB;
        display: flex;
        margin: 0 10px;
        padding: 0 0 15px 0;
        justify-content: space-between;
    }

    .modtwo .inps input {
        font-size: 14px;
    }

    .modtwo .inps image {
        width: 20px;
        height: 20px;
    }

    .modtwo .inps .feepri {
        font-size: 14px;
    }

    .modtwo .inps text {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        line-height: 24px;
        color: #7F6AC3;
    }

    .timo {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 38px;
        color: #FFFFFF;
        width: 710rpx;
        height: 38px;
        background: #7F6AC3;
        border-radius: 19px;
        text-align: center;
        margin: 40px auto 0;
    }

    .celldb {
        border-bottom: 1px solid #EBEBEB;
        margin: 0 20rpx;
        padding: 0 0 10rpx 0;
    }

    .celldb picker {
        width: 660rpx;

    }

    .celldb .uniinput {
        display: flex;
        justify-content: space-between;
        align-items: center;
        display: inline-block;

    }

    .celldb image {
        display: inline-block;
        width: 30rpx;
        height: 20rpx;
        float: right;
        margin: 10px 0 0 0;
    }
</style>
